package UnitTest;

import java.util.ArrayList;
import java.util.List;

/**
 * @Auther: arcadia
 * @Date: 20-2-2 16 01
 * @Description: 子集
 */
public class SubSets {


    public static void main(String[] args) {
        int[] nums = {1, 2, 3};
        List<List<Integer>> res = new ArrayList<>();
        List<Integer> cur = new ArrayList<>();
        helper(res, cur, 0, nums);
        System.out.println(res);
    }

    /**
     * @param res 结果集
     * @param cur 当前候选解
     * @param index 索引
     * @param nums 原集合
     *
     */
    public static void helper(List<List<Integer>> res, List<Integer> cur, int index, int[] nums) {
        if (index == nums.length) {
            res.add(new ArrayList<>(cur));
            return;
        }
        cur.add(nums[index]);
        helper(res, cur, index + 1, nums);
        cur.remove(cur.size() - 1);
        helper(res, cur, index + 1, nums);
    }
}
